import json

__author__ = 'wuliao'
# coding = utf-8

import requests
import lxml.etree


class SongList:
    def __init__(self, id):
        self.id = id
        self.url = "http://music.163.com/playlist?id=" + str(id)

    def get_data(self):
        response = requests.get(self.url)
        doc = lxml.etree.HTML(response.text)
        areas = doc.xpath("//*[@id=\"song-list-pre-cache\"]/ul/li/a")
        data = []
        for area in areas:
            id = area.xpath("@href")[0].replace("/song?id=", "")
            name = area.text
            data.append({'id': id, 'name': name})
        return data


#print SongList(1).get_data()